package ru.neoflex.jedit.plugin.core;

/**
 * Элемент списка автодополения
 */
public class Completion implements Comparable<Object> {
    private final String word;

    public Completion(String text) {
        if (text == null || text.length() == 0) {
            throw new IllegalArgumentException("Completion: the text" +
                    " must be not null and have at least 1 character");
        }
        this.word = text;
    }

    public String toString() {
        return word;
    }

    public int hashCode() {
        return word.hashCode();
    }

    public boolean equals(Object obj) {
        if (obj instanceof Completion)
            return ((Completion) obj).word.equals(word);
        else
            return false;
    }

    public String getWord() {
        return word;
    }

    public boolean hasPrefix(String prefix) {
        return word.startsWith(prefix) && (!word.equals(prefix));
    }

    public int compareTo(Object o) {
        return word.compareTo(((Completion) o).getWord());
    }
}